from db_connect import ConnMysqlSlave
import aiomysql
import asyncio

class ProductType():

    async def product_type(self,product_type_id):
        if not product_type_id:

            return {
                'status': -1,
                'errorCode': 2,
                'errorMsg':"请检查你的参数",
                'resultBody':None
            }

        
        sql="select * from product_info where product_type_id=%s"

        async with ConnMysqlSlave().pool.acquire() as conn:

            await conn.ping()

            async with conn.cursor(aiomysql.DictCursor) as cur:

                await cur.execute(sql,(product_type_id,))

                info = await cur.fetchall()

                for i in info:
                     
                    i["product_price"]=str(i["product_price"])


        if not info:

            return {
                'status': -1,
                'errorCode': 3,
                'errorMsg': "你查找的id号不存在",
                'resultBody': None,
            }



        return {
                'status': 1,
                'errorCode': None,
                'errorMsg': None,
                'resultBody': {"product_info":info},
            }


